/**
 * 添加或者修改页面
 */
var AppNoticeInfoDlg = {
    data: {
        title: "",
        pic: "",
        summary: "",
        content: "",
        createUser: "",
        ifReaded: "",
        status: "",
        sort: "",
        ifDel: "",
        createTime: "",
        updateTime: "",
        deleteTime: ""
    }
};


//单图改变图片
function setAttrPic(index,item){
    //this.attrs[index],'pic',pic);
    console.log('pic',item);
    console.log('index',index);
    $('#demo1').attr('src', item.url); //图片链接（base64）
    $('#pic').val(item.url); //图片链接（base64）

};

//获取选中的 图片

function changeIMG(index,pic){
    console.log(pic);
    setAttrPic(index,pic);
};

layui.use(['form', 'admin', 'ax','upload','formSelects','layer','func'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var upload = layui.upload;
    var formSelects = layui.formSelects;
    var layer = layui.layer;
    var func = layui.func;


    //实例化编辑器
    var ue = UE.getEditor('content', {
        enableAutoSave: false,
        autoHeightEnabled: true,
        autoFloatEnabled: false,
        scaleEnabled: true,         //滚动条
        initialFrameHeight: 400     //默认的编辑区域高度
    });

    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function (action) {
        if (action === 'uploadimage' || action === 'uploadscrawl' || action === 'uploadimage') {
            return Feng.ctxPath + '/ueditor/imgUpdate';
        } else if (action === 'uploadfile') {
            return Feng.ctxPath + '/ueditor/uploadfile';
        } else if (action === 'uploadvideo') {
            return Feng.ctxPath + '/ueditor/uploadvideo';
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    };


    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/appNotice/addItem", function (data) {
            Feng.success("添加成功！");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();

        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //上传图片
    $('.changeImg').on('click', function(){
        var file_type="";//文件类型
        var inputname="pic";//input 名称
        createFrame('选择图片',Feng.ctxPath + '/directoryFile/add',"",file_type,inputname);
    });

    function createFrame(title,src,opt,file_type,inputname){
        opt === undefined && (opt = {});
        return layer.open({
            type: 2,
            title:title,
            area: [(opt.w || 700)+'px', (opt.h || 520)+'px'],
            fixed: false, //不固定
            maxmin: true,
            moveOut:false,//true  可以拖出窗外  false 只能在窗内拖
            anim:5,//出场动画 isOutAnim bool 关闭动画
            offset:'auto',//['100px','100px'],//'auto',//初始位置  ['100px','100px'] t[ 上 左]
            shade:0,//遮罩
            resize:true,//是否允许拉伸
            content: src,//内容
            move:'.layui-layer-title',
            success: function (layero, index) {
                // 获取子页面的iframe
                var iframe = window['layui-layer-iframe' + index];
                // 向子页面的全局函数child传参
                var child_data={id:22,file_type:file_type,inputname:inputname};
                iframe.child(child_data);

            }

        });

    };

});